package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.Outing;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IOutingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库单Controller
 * 
 * @author ruoyi
 * @date 2021-05-08
 */
@RestController
@RequestMapping("/system/outing")
public class OutingController extends BaseController
{
    @Autowired
    private IOutingService outingService;

    /**
     * 查询出库单列表
     */
    @PreAuthorize("@ss.hasPermi('system:outing:list')")
    @GetMapping("/list")
    public TableDataInfo list(Outing outing)
    {
        startPage();
        List<Outing> list = outingService.selectOutingList(outing);
        return getDataTable(list);
    }

    /**
     * 查询出库单列表
     */
    //@PreAuthorize("@ss.hasPermi('system:outing:list')")
    @GetMapping("/QueryOuting")
    public TableDataInfo QueryOuting(Outing outing)
    {
        startPage();
        List<Outing> list = outingService.QueryOuting(outing);
        return getDataTable(list);
    }

    /**
     * 导出出库单列表
     */
    @PreAuthorize("@ss.hasPermi('system:outing:export')")
    @Log(title = "出库单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Outing outing)
    {
        List<Outing> list = outingService.selectOutingList(outing);
        ExcelUtil<Outing> util = new ExcelUtil<Outing>(Outing.class);
        return util.exportExcel(list, "出库单数据");
    }

    /**
     * 获取出库单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:outing:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(outingService.selectOutingById(id));
    }

    /**
     * 新增出库单
     */
    @PreAuthorize("@ss.hasPermi('system:outing:add')")
    @Log(title = "出库单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Outing outing)
    {
        return toAjax(outingService.insertOuting(outing));
    }

    /**
     * 修改出库单
     */
    @PreAuthorize("@ss.hasPermi('system:outing:edit')")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Outing outing)
    {
        return toAjax(outingService.updateOuting(outing));
    }

    /**
     * 删除出库单
     */
    @PreAuthorize("@ss.hasPermi('system:outing:remove')")
    @Log(title = "出库单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(outingService.deleteOutingByIds(ids));
    }
}
